package dev.ece.suit.loader.models.fbx;

import java.util.List;

public class FBXTexture {

	public final static String TEXTURE = "Texture";
	
	public final static String FILE_NAME = "FileName";
	
	public final static String RELATIVE_FILE_NAME = "RelativeFilename";
	
	public final static String TEXTURE_NAME = "TextureName";
	
	private String textureName;
	
	private String fileName;
	
	private String relativeFilename;
	
	private long id;
	
	private FBXTexture() {}
	
	public static FBXTexture[] parseFBXTexture(List<FBXElement> textureElements) {
		if(textureElements != null && !textureElements.isEmpty()) {
			FBXTexture[] textures = new FBXTexture[textureElements.size()];
			FBXElement[] elements = null;
			FBXElement element = null;
			for(int i=0; i<textures.length; i++) {
				textures[i] = new FBXTexture();
				element = textureElements.get(i);
				textures[i].id = (Long) element.getProperties()[0].getValue();
				elements = element.findChildren(TEXTURE_NAME);
				if(elements != null && elements.length > 0 && elements[0].hasProperties()) {
					textures[i].textureName = (String) elements[0].getProperties()[0].getValue();
				}
				elements = element.findChildren(FILE_NAME);
				if(elements != null && elements.length > 0 && elements[0].hasProperties()) {
					textures[i].fileName = (String) elements[0].getProperties()[0].getValue();
				}
				elements = element.findChildren(RELATIVE_FILE_NAME);
				if(elements != null && elements.length > 0 && elements[0].hasProperties()) {
					textures[i].relativeFilename = (String) elements[0].getProperties()[0].getValue();
				}
			}
			return textures;
		}
		return null;
	}

	public String getFileName() {
		return fileName;
	}

	public String getRelativeFilename() {
		return relativeFilename;
	}

	public String getTextureName() {
		return textureName;
	}

	public long getId() {
		return id;
	}

	@Override
	public String toString() {
		return new StringBuilder()
			.append("(fileName=").append(this.getFileName())
			.append(",\nrelativeFilename=").append(this.getRelativeFilename())
			.append(",\ntextureName=").append(this.getTextureName())
			.append(",\nid=").append(this.getId()).append(")").toString();
	}
	
	
}
